package com.qiedan.controller.mdy;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qiedan.bean.Orders;
import com.qiedan.dto.OrdersDto;
import com.qiedan.service.OrdersService;
import com.qiedan.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RequestMapping("/order")
@RestController
@Slf4j
public class OrdersController {

    @Autowired
    OrdersService ordersService;

    /**
     * 根据用户id获取该用户历史订单
     * @param uid
     * @return
     */
    @RequestMapping("/list")
    public R<Object> showOrdersList(Integer uid,Integer pageIndex,Integer pageSize){
        log.info("uid: "+uid);

       return ordersService.getOrdersListByUserId(uid, pageIndex, pageSize);
    }

    @RequestMapping("/add")
    public R<Object> add(@RequestBody Orders orders){
        log.info("order: "+orders.toString());

        Date date = new Date();
        orders.setCreatetime(date);
        orders.setStatus(1);
        ordersService.save(orders);
        R<Object> resp = new R<>();
        resp.setMsg("订单生成成功！");
        return resp;
    }
}

